﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DocumentStorage.EFRepository.Interfaces;
using DocumentStorage.Models;
using DocumentStorage.Services.Interfaces;
using NBehave.Spec.NUnit;
using NUnit.Framework;
using Ninject;

namespace DocumentStorage.IntegrationTests.DocumentService
{
  public class when_using_the_document_service : Specification
  {
    protected IDocumentPersistanceService _documentService;
    protected IDocumentRepository _documentRepository;
    protected StandardKernel _kernel;

    protected override void Establish_context()
    {
      base.Establish_context();

      _kernel = new StandardKernel(new IntegrationTestModule());
      _documentService = _kernel.Get<IDocumentPersistanceService>();
      _documentRepository = _kernel.Get<IDocumentRepository>();
    }
  }

  public class and_attempting_to_save_and_read_a_document_to_the_datastore : when_using_the_document_service
  {
    private Document _expected;
    private Document _result;

    protected override void Establish_context()
    {
      base.Establish_context();

      _expected = new Document {Id = 1};
    }

    protected override void Because_of()
    {
      _documentService.CreateDocument(_expected);
      _result = _documentService.GetDocument(_expected.Id);
    }

    [Test]
    public void then_the_document_saved_to_the_datastore_should_equal_the_document_retrieved()
    {
      _result.Id.ShouldEqual(_expected.Id);
    }
  }
}
